package com.lupan.spring.kafka.service;


import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.listener.MessageListener;
import org.springframework.stereotype.Component;


/**
 * 心跳kafka消费处理逻辑
 */
@Component
public class HeartbeatKafkaMsgListener implements MessageListener<String, String> {

    private static final Logger logger = LoggerFactory.getLogger(HeartbeatKafkaMsgListener.class);

    @Autowired
    private EcuVersionKafkaService ecuVersionKafkaService;

    @Override
    public void onMessage(ConsumerRecord<String, String> consumerRecord) {
        try {
            logger.debug("消费心跳kafka消息，内容：{}",consumerRecord.value());
            ecuVersionKafkaService.judgeIsSyncFromRedis(consumerRecord.value());
        } catch (Exception e) {
            try {
                logger.error("心跳kafka消息处理失败，失败消息：{}",consumerRecord.value());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            logger.error("心跳消息处理失败，异常栈：",e);
        }
    }
}
